\ Constants used in the cipher
255 Constant byteMax

\ Set our buffer to 1
: BUFFER_TRANSPOSITION ( -- ) 1 SET_BUFFER ;

\ Setup for transposition cipher
: SETUP_TRANSPOSITION ( -- )  BUFFER_TRANSPOSITION ;

\ Encrypt by transposing the byte 
: ENCRYPT_TRANSPOSITION ( -- ) SETUP_TRANSPOSITION
	READ_LINE
	0 EOF = IF
		
	ELSE
		BEGIN
			\ Fetch the char value, (CIPHERTEXT = MAX - PLAINTEXT)
			byteMax lineBuffer c@ - lineBuffer c!
			WRITE_LINE
			READ_LINE
			0 EOF =
		UNTIL
	ENDIF ;

\ Decrypt by transposing the byte
: DECRYPT_TRANSPOSITION ( -- ) SETUP_TRANSPOSITION
	READ_LINE
	0 EOF = IF
		
	ELSE
		BEGIN
			\ Fetch the char value, (PLAINTEXT = MAX - CIPHERTEXT)
			byteMax lineBuffer c@ - lineBuffer c!
			WRITE_LINE
			READ_LINE
			0 EOF =
		UNTIL
	ENDIF ;
